<?php
/**
 *
 * 输入content数组，输出组装好的pinboard HTML数组
 * 数据结构不统一的话在重写unique_data()；
 *
 * @param array $pin_data
 * 单条记录规则
 * array(
 *        'uid' =>        //visitor的uid
 *        'nick' =>
 *        'rid' =>
 *        'pic_id' =>
 *        'content' =>
 *        'like_cnt' =>
 *        'cmt_cnt' =>
 *        'quote_cnt' =>
 *     'gd_title' =>
 *     'gd_price' =>
 *     'deleteType'  =>关闭按钮的属性（1删除，2取消关注）
 *        'ctime' =>    // yyyy-mm-dd HH:ii:ss
 *        'is_attitude'    => //true/false
 *        'attitude_score'    => //int
 *        'is_quote' => //
 *     'quote_info' = array()//转采人说的话
 * )
 * @return unknown
 */

abstract class ml_biz_pin_abstract{


    private $aNicks = array();     //昵称数组
    private $aAttitude = array();  //是否表过态
    private $aLikeCnt = array();  //宝贝表态数
    private $aCmtCnt = array();  //宝贝评论数
    private $aQuoteCnt = array();//pin宝贝被转采数
    private $aPicHeight = array();
    private $redis;             //redis对象实例（防止多次实例化）
    private $pic_redis;             //picheight的redis

    protected $aUid = array();       //uid数组
    protected $aPic = array();       //picid数组
    protected $uniqueData=array();//统一格式的数组
    protected $ifme=true;        //是否是本人查看(用来判断是否显示右上角的关闭按钮)
    protected $uid;               //visitor的uid
    protected $ria = false;       //是否需要显示init  = false
    protected $aRid = array();       //资源id数组
    protected $aHTML = array();       //最终的数组
    protected $rds_nick;

    protected $is_favourite=false;//默认不是我的最爱（最爱不用判断是否表态）
    private $deleteType=array(); //关闭按钮的属性（1删除，2取消关注）

    public function __construct(){
        $this->redis = new ml_model_rdsCount();
        $this->rds_nick = new ml_model_rdsHash();
        $this->pic_redis = new ml_model_rdsPic();
    }


    /**
     *获取uid和rid数组
     */
    public function getUidRid(){
        if (empty($this->uniqueData))
        return false;

        foreach ($this->uniqueData as $value) {
            $this->aUid[]=$value['uid'];
            $this->aRid[]=$value['rid'];
            $this->aPic[]=$value['pic_id'];
        }
        $this->aPic=array_unique($this->aPic);
        $this->aUid=array_unique($this->aUid);

    }

    /**
     *重置是否是喜欢
     */
    public function set_is_favourite($is_favourite){

        $this->is_favourite=$is_favourite;
    }
    
    /**
     *重置是否是自己
     */
    public function set_ifme($ifme){

        $this->ifme=$ifme;
    }

    

    protected function unique_Data(){


    }

    /**
     *重置deleteType
     */
    public function set_deleteType($deleteType){
        $this->deleteType=$deleteType;
    }
    /**
     *重置ria
     */
    public function set_ria($ria){
        $this->ria=$ria;
    }

    /**
     *加昵称各种数。。。。。
     */
    public function parseData(){

        foreach ($this->uniqueData as &$content) {

            $content['nick']=$this->aNicks[$content['uid']];
            $content['like_cnt'] = intval($this->aLikeCnt[$content['rid']]);
            $content['cmt_cnt'] = intval($this->aCmtCnt[$content['rid']]);
            $content['quote_cnt'] = intval($this->aQuoteCnt[$content['rid']]);
            $content['pic_height'] = intval($this->aPicHeight[$content['pic_id']]);
            if ($this->is_favourite && $this->ifme){//是最爱  并且是自己
                $content['is_attitude'] = true;
            }else{
                $content['is_attitude'] = isset($this->aAttitude[$content['rid']]) ? true : false;
            }
            $content['attitude_score'] = $this->aAttitude[$content['rid']];
        }
        

        return ml_tool_pinOutput::parsePinboardTpl($this->uniqueData,$this->ifme);



    }

    /**
     *用获得的uid数组统一去redis去查nick
     */
    public function get_nick()
    {
        $this->aNicks = ml_tool_nick::uids2nicks($this->aUid);
    }

    /**
     *用获得的rid数组统一去redis去查表态数
     */
    public function get_cnt()
    {
        $rs = $this->redis->getAttitudeCount($this->aRid);
        /**
         * @todo
         */
        $this->aLikeCnt = $this->redis->get_data();

    }

    /**
     *用获得的rid数组统一去redis去查是否表过态
     */
    public function get_attitude()
    {
        if($this->uid)
        {
            $oIlike = new ml_model_dbILike();
            $rs = $oIlike->getListByUidRids($this->uid , $this->aRid);
            $this->aAttitude = Tool_array::format_2d_array($oIlike->get_data() , 'content_rid' , Tool_array::FORMAT_VALUE2VALUE2 ,'attitude');
        }
    }

    /**
     *获得评论
     */
    public function  get_comment(){
        $rs = $this->redis->getCommentCount($this->aRid);
        /**
         * @todo
         */
        $this->aCmtCnt = $this->redis->get_data();

    }

    /**
     *获得采集数
     */
    public function  get_ColCnt(){
        $rs = $this->redis->getColCnt($this->aRid);
        /**
         * @todo
         */
        $this->aQuoteCnt = $this->redis->get_data();

    }

    /**
     *获得高度
     */
    public function  get_PicHeight($size = 'pin'){
        foreach ($this->aPic as $value) {
            $this->aPicHeight[$value] = ml_tool_picid::pid2h($value , $size);
        }
        return ;        

        $re = $this->pic_redis->getPicPinHeight($this->aPic);
        $this->aPicHeight = $this->pic_redis->get_data();

    }



}
?>